
<% @page_title = @topic.title %>
<% @monitoring = logged_in? && !Monitorship.count(:all, :conditions => ['user_id = ? and topic_id = ? and active = ?', current_user.id, @topic.id, true]).zero? %>

<% content_for :right do -%>

<h5><%= _('Voices') %></h5>
<ul class="flat talking">
<% @topic.voices.each do | user | %>
  <li><%= link_to h(user.display_name), user_path(user) %></li>
<% end %>
</ul>


<% end # right content -%>

<% if logged_in? %>

<% form_tag monitorship_path(@forum, @topic), :style => 'margin-top:0em; float:right;' do -%>

<% end -%>

<% end -%>

<div class="crumbs">
  <%= link_to _("Ruby on Rails Chinese Community"), home_path %> <span class="arrow">&rarr;</span>
  <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %> 
  <% 
  page=session[:forum_page] ? session[:forum_page][@topic.forum.id] : nil
  if page and page!=1 %>
  <small style="color:#ccc">
  (<%= link_to _('page') + " #{page}", forum_path(:id => @topic.forum, :page => page) %>)
  </small>
  <% end %>
  <span class="arrow">&rarr;</span>
</div>

<h1 id="topic-title" style="margin-top:0.5em;"<%= %( onmouseover="$('topic_mod').show();" onmouseout="$('topic_mod').hide();") if logged_in? %>>


  <%= h @topic.title %>
  <% if @topic.locked? %>
  <span><%= _('(locked)') %></span>
  <% end %>
  <% if logged_in? %>
    <span style="display:none;" id="topic_mod">
      <% if @topic.editable_by?(current_user) -%>
        <%= link_to(_('edit'), edit_topic_path(@forum, @topic), :class => "utility") %> |
        <%= link_to(_('delete'), topic_path(@forum, @topic), :class => "utility", :method => :delete, :confirm => _('Delete this topic forever?')) %>
      <% end -%>
    </span>
  <% end %>
</h1>

<p class="subtitle">
  <%= feed_icon_tag @topic.title, formatted_topic_path(@forum, @topic, :rss) %>
  <%= "#{@topic.posts.count}"+ _('post') %>, <%= "#{@topic.voice_count}"+ _('voice') %>
</p>

<% if @post_pages.page_count > 1 -%>
<p class="pages"><%= _('Pages:') %> <strong><%= pagination_links @post_pages, :window_size => 10 %></strong></p>
<% end -%>

<a name="<%= @posts.first.dom_id %>" id="<%= @posts.first.dom_id %>">&nbsp;</a>

<table border="0" cellspacing="0" cellpadding="0" class="posts wide">
<% for post in @posts do %>
<% unless post == @posts.first %>
<tr class="spacer">
  <td colspan="2">
    <a name="<%= post.dom_id %>" id="<%= post.dom_id %>">&nbsp;</a>
  </td>
</tr>
<% end %>
<tr class="post hentry" id="<%= post.dom_id %>-row">
  <td class="author vcard">
    <div class="date">
      <a href="#<%= post.dom_id %>" rel="bookmark">
      <abbr class="updated" title="<%= post.created_at.xmlschema %>">
      <%= time_ago_in_words(post.created_at) %>
      </abbr>
      </a>
    </div>

    <%= avatar_for post.user %>
    <span class="fn"><%= link_to truncate(h(post.user.display_name), 15), user_path(post.user), :class => (post.user == @posts.first.user ? "admin" : nil) %></span>
    <span class="posts"><%= "#{post.user.posts_count}"+ _('post') %></span>

    <% if logged_in? && post.editable_by?(current_user) -%>
    <p>
      <span class="edit">
        <%= ajax_spinner_for "edit-post-#{post.id}", "spinner_bounce.gif" %>
        <%= link_to_remote(_('Edit post'), 
              {:url => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post), :method => :get,
               :before => "EditForm.init(#{post.id});", :condition => "!EditForm.isEditing(#{post.id})" }, 
              {:href => edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post, :page => params[:page]), :class => "utility"}) %>
      </span>
    </p>
    <% end -%>


  </td>
  <td class="body entry-content">
<!--
    <%= link_to_function image_tag('clearbits/comment.gif', :class => 'icon reply'), "$('reply').toggle()" if logged_in? %>
-->
    <div id="post-body-<%= post.id %>"><%= post.body_html %></div>
	<%= render :partial => "posts/attachment_show", :locals => {:post => post,:source => 'show'} %>
  </td>
</tr>

<% end %>
</table>
<iframe id='upload_frame' name="upload_frame" style="width:1px;height:1px;border:0px" src="about:blank"></iframe>

<% if @post_pages and @post_pages.current.next %>
<p style="float:right;"><%= link_to _("Next page"), { :page => @post_pages.current.next }.merge(params.reject{|k,v| k=="page"})  %></p>
<% end %>

<% if @post_pages.page_count > 1 -%>
<p class="pages">Pages: <strong><%= pagination_links @post_pages, :window_size => 10 %></strong></p>
<% end -%>

<% if logged_in? %>
<div id="edit"></div>
<% if @topic.locked? %>
<p>
    <%= image_tag "clearbits/lock.gif", :class => "icon grey", :title => "Topic locked" %> 
    <label>
    <%= _('This topic is locked.') %></label>
</p>
<% else %>

<p><%= link_to_function _('Reply to topic'), "ReplyForm.init()", :class => "utility" %></p>

<div id="reply" class="editbox">
<div class="container">
  <%= content_tag 'p', h(flash[:bad_reply]), :class => 'notice' if flash[:bad_reply] %>
  <% form_for :post, :html => {:multipart => true}, :url => posts_path(:forum_id => @forum, :topic_id => @topic, :page => @topic.last_page) do |f| -%>
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td rowspan="2" width="70%">
        <p><%= f.text_area :body, :rows => 8 %></p>
		<p><%= render :partial => "posts/attachment_show", :locals => {:post => @post,:source => 'edit'} %></p>
		<p><%= render :partial => "topics/attachment_form", :locals => {:text_area_id => 'edit_post_body'}%></p>
      </td>
      <td valign="top">


        <h5><%= _('Formatting Help') %></h5>

        <ul class="help"><br />
          <li><%= _('*bold*') %><br />格式说明： *(文字)*  文字则显示为粗体<br />
          <br />
          <%= _('_italics_') %><br />格式说明：_(文字)_  文字则显示为斜体<br />
         
        </ul>

      </td>
    </tr>
    <tr>
      <td valign="bottom" style="padding-bottom:15px;">
       <%= submit_tag _("Save Reply") %><span class="button_or">or <%= link_to_function _('cancel'), "$('reply').hide()" %></span>
     </td>
   </tr>
  </table>
  <% end -%>
</div>
</div>
<%= javascript_tag "$('reply').hide();"%>
<% end %>
<% end %>

<div class="crumbs" style="margin-top:1.1em;">
  <%= link_to _("Ruby on Rails Chinese Community"), home_path %> <span class="arrow">&rarr;</span>
  <%= link_to h(@topic.forum.name), forum_path(@topic.forum) %> <span class="arrow">&rarr;</span>
</div>
